package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.User;
import com.cskaoyan.bean.wx.vo.WxFeedbackSubmit;
import com.cskaoyan.service.UserService;
import com.cskaoyan.utils.RegisterUtil;
import com.cskaoyan.utils.ShiroGetSubjectMessageUtil;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author tangjian
 * @Date 2021/10/21 15:53
 * @description
 */
@RestController
@RequestMapping("/wx/feedback")
public class WxFeedbackController {
    @Autowired
    UserService userService;

    @RequestMapping("submit")
    public BaseRespVo wxFeedbackSubmit(@RequestBody WxFeedbackSubmit wxFeedbackSubmit){


        String mobile = wxFeedbackSubmit.getMobile();
        //校验格式
        if (!RegisterUtil.checkPhone(mobile) &&
                !RegisterUtil.checkEmail(mobile))
            return BaseRespVo.fail("手机号格式不对");

        User user = ShiroGetSubjectMessageUtil.getUser();
        if (user == null){
            //匿名用户
            user.setUsername("anonymous");
            user.setId(0);
        }
        int i = userService.feedbackInsert(wxFeedbackSubmit,user);

        return BaseRespVo.ok();
    }

}
